package cn.tedu.micro.demo.direct;

import cn.tedu.micro.demo.client.RabbitChannelManager;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import org.junit.Test;

import java.io.IOException;

/**
 * 声明路由交换机,绑定队列
 * 测试消息的路由结果
 */
public class DirectDemo {
    @Test
    public void declareDirect() throws Exception {
        //1.拿到客户端
        Channel channel= RabbitChannelManager.newChannel();
        //2.声明3个队列
        channel.queueDeclare("queue1", false, false, false, null);
        channel.queueDeclare("queue2", false, false, false, null);
        channel.queueDeclare("queue3", false, false, false, null);
        //3.声明一个路由交换机
        channel.exchangeDeclare("direct_ex", BuiltinExchangeType.DIRECT);
        //4.声明绑定关系 上海 北京 天津
        channel.queueBind("queue1","direct_ex","北京");
        channel.queueBind("queue2","direct_ex","上海");
        channel.queueBind("queue3","direct_ex","天津");
    }
}
